package com.ryskoo.permission.rolepermissionrel.repository;

import com.ryskoo.common.constant.CacheConstant;
import com.ryskoo.framework.core.repository.BasicRedisImpl;
import com.ryskoo.framework.core.utils.RedisUtil;
import com.ryskoo.permission.rolepermissionrel.domain.RolePermissionRelPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;

@Primary
@Repository
public class RolePermissionRelRedisImpl extends BasicRedisImpl<RolePermissionRelPO> implements IRolePermissionRelRepository {

	@Autowired
	private RedisUtil redisClient;

	@Autowired
	private IRolePermissionRelRepository rolePermissionRelRepository;

	@PostConstruct
	public void init() {
		this.setRedisClient(redisClient);
		this.setDao(rolePermissionRelRepository);
	}

	public RolePermissionRelRedisImpl() {
		super(CacheConstant.PMS_ROLE_PERMISSION_REL_KEY);
	}

	/**
	 * 根据角色id删除角色与权限的关联关系
	 *
	 * @param roleId 角色id
	 */
	@Override
	public void deleteRolePermissionRelByRoleId(String roleId) {
        rolePermissionRelRepository.deleteRolePermissionRelByRoleId(roleId);
	}

}
